1
|
|
|
/** |
2
|
|
|
dark |
3
|
|
|
Component that handles dark matter and second prestige logic. |
4
|
|
|
It handles dark matter production and dark upgrades. |
5
|
|
|
A second prestige resets the progress of all elements with exotic |
6
|
|
|
matter and produces dark matter. |
7
|
|
|
|
8
|
|
|
@namespace Components |
9
|
|
|
*/ |
10
|
|
|
'use strict'; |
11
|
|
|
|
12
|
|
|
angular.module('game').component('dark', { |
13
|
|
|
templateUrl: 'views/dark.html', |
14
|
|
|
controller: 'ct_dark', |
15
|
|
|
controllerAs: 'ct' |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
angular.module('game').controller('ct_dark', ['state', 'format', 'visibility', 'upgrade', 'data', 'util', |
19
|
|
|
function(state, format, visibility, upgrade, data, util) { |
20
|
|
|
let ct = this; |
21
|
|
|
ct.state = state; |
22
|
|
|
ct.data = data; |
23
|
|
|
ct.util = util; |
24
|
|
|
ct.format = format; |
25
|
|
|
ct.cache = { |
26
|
|
|
breakdown: {} |
27
|
|
|
}; |
28
|
|
|
|
29
|
|
|
ct.update = function(player) { |
30
|
|
|
refresh(player); |
31
|
|
|
}; |
32
|
|
|
|
33
|
|
|
/* Refreshes the values in the cache */ |
34
|
|
|
function refresh(player) { |
35
|
|
|
ct.cache.breakdown = {}; |
36
|
|
|
for (let element in data.elements) { |
37
|
|
|
let exotic = data.elements[element].exotic; |
38
|
|
|
if (player.resources[exotic] === null || !player.statistics.dark_run[exotic]) { |
39
|
|
|
continue; |
40
|
|
|
} |
41
|
|
|
let number = player.statistics.dark_run[exotic]; |
42
|
|
|
let darkProduction = util.prestigeProduction(number, data.constants.DARK_START, data.constants.DARK_STEP); |
43
|
|
|
ct.cache.breakdown[exotic] = Math.round(Math.max(0, darkProduction)); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
ct.darkProduction = function() { |
48
|
|
|
let production = 0; |
49
|
|
|
for (let resource in ct.cache.breakdown) { |
50
|
|
|
production += ct.cache.breakdown[resource]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return production; |
54
|
|
|
}; |
55
|
|
|
|
56
|
|
|
ct.darkPrestige = function(player) { |
57
|
|
|
let production = ct.darkProduction(); |
58
|
|
|
|
59
|
|
|
util.addResource(player, 'all_time', 'dark_matter', production, state); |
60
|
|
|
|
61
|
|
|
for (let key in data.elements) { |
62
|
|
|
let element = data.elements[key]; |
63
|
|
|
if(player.resources[element.exotic] !== null){ |
64
|
|
|
player.resources[element.exotic] = 0; |
65
|
|
|
} |
66
|
|
|
if (!player.exotic_upgrades[key]) { |
67
|
|
|
continue; |
68
|
|
|
} |
69
|
|
|
for (let up in data.exotic_upgrades) { |
70
|
|
|
player.exotic_upgrades[key][up] = false; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
for (let slot of player.element_slots) { |
74
|
|
|
if (!slot) { |
75
|
|
|
continue; |
76
|
|
|
} |
77
|
|
|
upgrade.resetElement(player, slot.element); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
for (let i in player.element_slots) { |
81
|
|
|
player.element_slots[i] = null; |
82
|
|
|
} |
83
|
|
|
player.statistics.exotic_run = {}; |
84
|
|
|
player.statistics.dark_run = {}; |
85
|
|
|
}; |
86
|
|
|
|
87
|
|
|
ct.buyDarkUpgrade = function(name, player) { |
88
|
|
|
let upgrades = player.dark_upgrades; |
89
|
|
|
let price = data.dark_upgrades[name].price; |
90
|
|
|
let currency = 'dark_matter'; |
91
|
|
|
upgrade.buyUpgrade(player, |
92
|
|
|
upgrades, |
93
|
|
|
data.dark_upgrades[name], |
94
|
|
|
name, |
95
|
|
|
price, |
96
|
|
|
currency); |
97
|
|
|
}; |
98
|
|
|
|
99
|
|
|
ct.visibleDarkUpgrades = function(player) { |
100
|
|
|
return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0, null, player); |
101
|
|
|
}; |
102
|
|
|
|
103
|
|
|
// here we receive not the name of the element, but the index in the element_slots |
104
|
|
|
function isDarkUpgradeVisible(name, index, player) { |
105
|
|
|
return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name], player); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
state.registerUpdate('dark', ct.update); |
109
|
|
|
refresh(state.player); |
110
|
|
|
} |
111
|
|
|
]); |
112
|
|
|
|